﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace TR0217.ControlEx
{
    public class NavigateMenuItemCollection : IList, ICollection, IEnumerable
    {
        private NavigateBar _navigateBar;
        private List<NavigateMenuItem> _innerList = new List<NavigateMenuItem>();
        internal List<NavigateMenuItem> InnerList
        {
            get { return _innerList; }
            set { _innerList = value; }
        }
        internal NavigateMenuItemCollection(NavigateBar navigateBar)
        {
            _navigateBar = navigateBar;
        }

        public void Add(NavigateMenuItem item)
        {
            _innerList.Add(item);
        }

        public void Clear()
        {
            _innerList.Clear();
        }

        public bool Contains(NavigateMenuItem item)
        {
            return _innerList.Contains(item);
        }

        public void CopyTo(NavigateMenuItem[] items, int index)
        {
            _innerList.CopyTo(items, index);
        }

        private int IndexOf(NavigateMenuItem item)
        {
            return _innerList.IndexOf(item);
        }

        public void Insert(int index, NavigateMenuItem item)
        {
            _innerList.Insert(index, item);
        }

        public void Remove(NavigateMenuItem item)
        {
            _innerList.Remove(item);
        }

        public void RemoveAt(int index)
        {
            _innerList.RemoveAt(index);
        }

        public int Count
        {
            get { return _innerList.Count; }
        }
        /// <summary>
        /// Gets a value indicating whether the collection is read-only. 
        /// </summary>
        public bool IsReadOnly
        {
            get { return false; }
        }

        public NavigateMenuItem this[int index]
        {
            get { return _innerList[index]; }
        }

        #region IEnumerable 成员

        public IEnumerator GetEnumerator()
        {
            return _innerList.GetEnumerator();
        }

        #endregion

        #region IList 成员

        int IList.Add(object value)
        {
            NavigateMenuItem item = value as NavigateMenuItem;
            this.Add(item);
            return this.IndexOf(item);
        }

        void IList.Clear()
        {
            this.Clear();
        }

        bool IList.Contains(object value)
        {
            return this.Contains(value as NavigateMenuItem);
        }

        int IList.IndexOf(object value)
        {
            return this.IndexOf(value as NavigateMenuItem);
        }

        void IList.Insert(int index, object value)
        {
            this.Insert(index, value as NavigateMenuItem);
        }

        bool IList.IsFixedSize
        {
            get { return false; }
        }

        bool IList.IsReadOnly
        {
            get { return this.IsReadOnly; }
        }

        void IList.Remove(object value)
        {
            this.Remove(value as NavigateMenuItem);
        }

        void IList.RemoveAt(int index)
        {
            this.RemoveAt(index);
        }

        object IList.this[int index]
        {
            get
            {
                return this[index];
            }
            set
            {
                throw new Exception("The method or operation is not implemented.");
            }
        }

        #endregion

        #region ICollection 成员

        void ICollection.CopyTo(Array array, int index)
        {
            ((ICollection)_innerList).CopyTo(array, index);
        }

        int ICollection.Count
        {
            get { return this.Count; }
        }

        bool ICollection.IsSynchronized
        {
            get { return false; }
        }

        object ICollection.SyncRoot
        {
            get { throw new Exception("The method or operation is not implemented."); }
        }

        #endregion
    }
}
